package cn.bugstack.test.domain.strategy;

import cn.bugstack.domain.strategy.model.vo.*;
import cn.bugstack.domain.strategy.service.rule.tree.factory.DefaultTreeFactory;
import cn.bugstack.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;


@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
/**
 * 规则树测试
 * */
public class LogicTreeTest {
    @Resource
    private DefaultTreeFactory defaultTreeFactory;

    @Test
    public void test_tree_rule() {
        RuleTreeNodeVo rule_lock = RuleTreeNodeVo.builder()
                .treeId(String.valueOf(1000001))
                .ruleKey("rule_lock")
                .ruleDesc("限定用户已完成N次抽奖后解锁")
                .ruleValue("1")
                .treeNodeLineVoList(new ArrayList<RuleTreeNodeLineVo>() {{
                    add(RuleTreeNodeLineVo.builder()
                            .treeId(String.valueOf(1000001))
                            .ruleNodeFrom("ruck_lock")
                            .ruleNodeTo("rule_luck_award")
                            .ruleLimitType(RuleLimitTypeVo.EQUAL)
                            .ruleLimitValue(RuleLogicCheckTypeVo.TAKE_OVER)
                            .build());
                    add(RuleTreeNodeLineVo.builder()
                            .treeId(String.valueOf(1000001))
                            .ruleNodeFrom("ruck_lock")
                            .ruleNodeTo("rule_stock")
                            .ruleLimitType(RuleLimitTypeVo.EQUAL)
                            .ruleLimitValue(RuleLogicCheckTypeVo.ALLOW)
                            .build());
                }})
                .build();

        RuleTreeNodeVo rule_luck_award = RuleTreeNodeVo.builder()
                .treeId(String.valueOf(1000001))
                .ruleKey("rule_luck_award")
                .ruleDesc("积分兜底策略")
                .ruleValue("1")
                .treeNodeLineVoList(null)
                .build();



        RuleTreeNodeVo rule_stock = RuleTreeNodeVo.builder()
                .treeId(String.valueOf(1000001))
                .ruleKey("rule_stock")
                .ruleDesc("库存处理规则")
                .ruleValue(null)
                .treeNodeLineVoList(new ArrayList<RuleTreeNodeLineVo>() {{
                    add(RuleTreeNodeLineVo.builder()
                            .treeId(String.valueOf(1000001))
                            .ruleNodeFrom("ruck_lock")
                            .ruleNodeTo("rule_luck_award")
                            .ruleLimitType(RuleLimitTypeVo.EQUAL)
                            .ruleLimitValue(RuleLogicCheckTypeVo.TAKE_OVER)
                            .build());
                }})
                .build();

        RuleTreeVo ruleTreeVo = new RuleTreeVo();
        ruleTreeVo.setTreeId(String.valueOf(1000001));
        ruleTreeVo.setTreeName("决策树规则：增加dall-e-3画图模型");
        ruleTreeVo.setTreeDesc("决策树规则：增加dall-e-3画图模型");
        ruleTreeVo.setTreeRootRuleNode("rule_lock");

        ruleTreeVo.setTreeNodeMap(new HashMap<String,RuleTreeNodeVo>(){{
            put("rule_lock",rule_lock);
            put("rule_stock",rule_stock);
            put("rule_luck_award",rule_luck_award);
        }});
        IDecisionTreeEngine treeEngine = defaultTreeFactory.openLogicTree(ruleTreeVo);


    }

}
